package com.hht.baselibs.listener

import android.os.SystemClock
import android.view.View


/**
 * Author:chen'hu
 * Time:2024/3/20 17:22
 * Description:防抖点击事件
 */
class AntiShakeClickListener(
    private val duration: Long = 500L,
    private val onClick: (View) -> Unit,
) : View.OnClickListener {
    private var lastClickTime: Long = 0
    override fun onClick(v: View) {
        val nowTime = SystemClock.elapsedRealtime()
        if (nowTime - lastClickTime >= duration) {
            lastClickTime = nowTime
            onClick.invoke(v)
        }
    }
}